package commands;

import java.io.IOException;

import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HTable;

import util.Utils;
import vo.Vote;

public class RemoveVoteCommand implements Comando {

	@Override
	public String execute(String[] args) throws IOException {
		if (args.length != 2) {
			return getSintaxe();
		}
		HTable table = new HTable(Vote.TABLENAME);
		byte [] voteId = Utils.createStringInBytes(args[1]);
		Get get = new Get(voteId);
		if(table.exists(get)){
			Delete delete = new Delete(voteId);
			table.delete(delete);
			return "Deletado com Sucesso: " + args[1];
		}
		
		return "VoteId inexistente: " + args[1];
	}

	@Override
	public String getKey() {
		return "-removeVote";
	}

	@Override
	public String getSintaxe() {
		return "-removeVote voteId";
	}

}
